/**
 * @file STL_Semaphore.h
 * @author Derek Liu (yjkhtddx@sina.com)
 * @brief 
 * @version 2.00.05
 * @date 2022-01-25
 * 
 * @coryright Copyright Sci-Tech Laboratories (c) 2022
 * 
 */

#include <mutex>
#include <condition_variable>

using namespace std;

namespace STL
{
    class STL_Semaphore
    {
    public:
        STL_Semaphore() = default;
        ~STL_Semaphore() = default;

        void notify_one()
        {
            cv.notify_one();
        }

        void notify_all()
        {
            cv.notify_all();
        }

        void wait(unique_lock<mutex> &lock)
        {
            cv.wait(lock);
        }

        template <typename _Rep, typename _Period>
        cv_status wait_for(unique_lock<mutex> &lock, const chrono::duration<_Rep, _Period> &rtime)
        {
            cv.wait_for(lock, rtime);
        }

        template <typename _Clock, typename _Duration>
        cv_status wait_until(unique_lock<mutex> &lock, const chrono::time_point<_Clock, _Duration> &atime)
        {
            cv.wait_until(lock, atime);
        }

    private:
        condition_variable cv;
    };

} // namespace STL
